﻿/*
Extends liteGrid with support for rich formatting of values.

Author: MBH
DateAuthored: 7/29/09  
*/

//Extends liteGrid with support for rich formatting of values.
function FormatModule() {
	var base = this;

	//Ties in to the liteGrid events that are needed to format values.
	base.initialize = function(liteGrid, options) {
		liteGrid.$el.bind("columnBound", base.columnBound);

		base.liteGrid = liteGrid;
		base.options = options;
	}

	//Callback that is run when the value of a cell changes.
	base.columnBound = function(event) {
	    var column = event.column;
	    var element = event.element;

		//TODO: Add type-based formatting? 

		//If the column defines a custom formatter, invoke it.
		if (column.formatter) {
			//Extract the raw data item
			var dataItem = element.parent().data("dataItem");
			column.formatter(column, element, dataItem);
		}
	}
}